/*
 * @Descripttion: 
 * @Author: liys
 * @LastEditTime: 2021-07-05 17:01:17
 * @Email: 21555@sohu.com
 */
$(function(){
		var iLineID = $("#PlanLineName").val();
		var url = "planJson?iLineID=" + iLineID;
		/*初始化表格*/
		$('#dg').datagrid({
    		url:url,
    		collapsible:true,
    		fit:true,
			fitColumns:true,
			toolbar:'#footer',
			pagination:true,
			pageSize:20,
			pageList:[20,50,100,200],
			remoteSort:false,
			onLoadSuccess:function(data){
		        if (data.total == 0) { 
				//colspan为实际显示的总列数，appendRow、mergeCells不用修改
				$(this).datagrid('appendRow', { lineName: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'planName', colspan: 6 }) 
				//隐藏分页导航条
				$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide(); 
				//隐藏选择框
				 $(this).datagrid('hideColumn', 'ck');
				} 
				//有数据时显示选择框、分页导航条
				else {
					$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();
					$(this).datagrid('showColumn', 'ck');}
		    },
   			columns:[[
				//width留2%给滚动条，其他自行调整
   			 	{field:'ck',checkbox:true},
   			 	{field:'planID',hidden:'true'},
				{field:'standard',title:'标准',align:'center',width:'15%',
				 formatter:function(value,row,index){
					if(row.planID == undefined)return row.standard;
					return'<a href="lineplaninfo?iPlanID='+row.planID+'">'+row.standard+'</a>'
				}},
				{field:'lineName',title:'线路名称',align:'center',width:'15%'},
				{field:'startDate',title:'开始日期',align:'center',width:'20%',formatter:function(value) {
		            var date = new Date(value);
		            var year = date.getFullYear().toString();
		            var month = (date.getMonth() + 1);
		            var day = date.getDate().toString();
		            if (month < 10) {
		                month = "0" + month;
		            }
		            if (day < 10) {
		                day = "0" + day;
		            }
		            return year + "-" + month + "-" + day;
		        }},
				{field:'endDate',title:'结束日期',align:'center',width:'20%',formatter:function(value) {
		            var date = new Date(value);
		            var year = date.getFullYear().toString();
		            var month = (date.getMonth() + 1);
		            var day = date.getDate().toString();
		            if (month < 10) {
		                month = "0" + month;
		            }
		            if (day < 10) {
		                day = "0" + day;
		            }
		            return year + "-" + month + "-" + day;
		        }},
				{field:'number',title:'数量',align:'center',width:'10%'},
				{field:'memo',title:'备注',align:'center',width:'18%'}
    		]]
		});
});

/* 切换线路 */
function changeLine(){
	var iLineID = $("#PlanLineName").val();
	location.href="/mmy/surroudingplan?iLineID="+iLineID;
}
/* 修改线路计划信息 */
function updateLinePlan(){		
	
	var rows = $('#dg').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 }else{
			var iPlanID = rows[0].planID;
			location.href="/mmy/toupdatelineplan?iPlanID="+iPlanID;		 
		}	
}

	
/* 删除线路计划信息 */
function delLinePlanBatch(){
	var checkNum = $("input[name='ckone']:checked").length;

    if(checkNum==0){
       var txt=  "至少选择一项";
 	window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.warning);
    }else{
		var txt = "确定要删除吗";
		window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.confirm,{onOk:function(){		
			var checklist = new Array();
        	$("input[name='ckone']:checked").each(function () {
            checklist.push($(this).val());
			
			$.ajax({
       		 url:"/mmy/deletelineplanchecked",
        	 type:"post",
        	 data:{
             checkList:checklist.toString()

             },
		     dataType:"text",
		     success:function () {
				
		        	var txt=  "删除成功";
					window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.success,{onOk:function(){
							location.reload();						
						}});	
		        	},
		     error:function () {
		        var txt=  "删除失败";
				window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
		       		 }
		   		 })
        	});	
		}});
	}
}


